package com.ruibang.glass.quality.controller;

import com.ruibang.glass.quality.domain.req.QualityContactReq;
import com.ruibang.glass.quality.entity.QualityContact;
import com.ruibang.glass.quality.service.QualityContactService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import com.teaming.cloud.framework2.common.pojo.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * <p>
 * 品质联络单信息 前端控制器
 * </p>
 *
 * @author wujie
 * @since 2023-11-30
 */
@RestController
@RequestMapping("/api/glass/quality/contact")
@Api(value="品质联络单信息操作接口",tags={"品质联络单信息操作接口"})
public class QualityContactController {

    @Autowired
    private QualityContactService qualityContactService;

    /**
    * 通过id查询
    */
    @GetMapping("/getById/{contactId}")
    @ApiOperation(value="获取品质联络单",notes="获取品质联络单")
    public ResultBody getById(@PathVariable(value = "contactId") String contactId){
        return ResultBody.success(qualityContactService.getDetail(contactId));
    }

    /**
    * 新增
    */
    @PostMapping("/save")
    @ApiOperation(value="新增品质联络单",notes="新增品质联络单")
    public ResultBody save(@RequestBody QualityContact qualityContact){
        qualityContactService.saveInfo(qualityContact);
        return ResultBody.success();
    }

    /**
    * 通过id删除
    */
    @GetMapping("/deleteById/{contactId}")
    @ApiOperation(value="通过ID删除品质联络单",notes="通过ID删除品质联络单")
    public ResultBody delete(@PathVariable(value = "contactId") String contactIds){
        String[] idsStrs = contactIds.split(",");
        qualityContactService.removeBatchByIds(Arrays.asList(idsStrs));
        return ResultBody.success();
    }

    /**
    * 修改
    */
    @PostMapping("/update")
    @ApiOperation(value="修改品质联络单",notes="修改品质联络单")
    public ResultBody updateInfo(@RequestBody QualityContact qualityContact){
        qualityContactService.updateInfo(qualityContact);
        return ResultBody.success();
    }


    /**
    * 查询列表
    */
    @PostMapping("/list")
    @ApiOperation(value="非分页列表查询品质联络单",notes="非分页列表查询品质联络单")
    public ResultBody list(@RequestBody QualityContactReq qualityContact){
        return ResultBody.success(qualityContactService.queryQualityContacts(qualityContact));
    }

    /**
    * 分页查询
    */
    @PostMapping("/page")
    @ApiOperation(value="分页列表查询品质联络单",notes="分页列表查询品质联络单")
    public ResultBody page(@RequestBody PageRequest<QualityContactReq> pageParam){
        return ResultBody.success(qualityContactService.queryPage(pageParam));
    }

}
